package com.ssh.controller.mechanic;

import com.common.service.CommonService;
import com.common.tool.Message;
import com.common.tool.Page;
import com.common.tool.PagingTool;
import com.ssh.entity.Mechanic;
import com.ssh.service.MechanicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 文 件 名 称：MechanicController.
 * 文 件 说 明：技工控制类
 * 创   建   人：zpen.
 * 创 建 时 间：2018/9/10 11:12.
 */
@Controller
@RequestMapping(value = "mechanic.action")
public class MechanicController {

    @Autowired
    MechanicService service;

    @Resource
    CommonService commonService;

    @RequestMapping
    public String goPage(){
        return "mechanic/mechanic";
    }

    @RequestMapping(params = "method=create")
    public String create(Model model,Mechanic mechanic){
        if(mechanic!=null&&mechanic.getId()!=null&&!"".equals(mechanic.getId())){
            Mechanic mechanic1 = (Mechanic) commonService.getEntity(Mechanic.class,mechanic.getId());
        }
        return "mechanic/create";
    }

    @RequestMapping(params = "method=getData")
    @ResponseBody
    public PagingTool getData(Mechanic mechanic, Page page){
        PagingTool pagingTool = service.queryForPage(mechanic,page);
        return pagingTool;
    }

    @RequestMapping(params = "method=saveMechanic")
    @ResponseBody
    public Message saveMechanic(Mechanic mechanic){
        Message message = new Message();
        Long proof = service.saveMechanic(mechanic);
        return message;
    }

    @RequestMapping(params = "method=delMechanic")
    @ResponseBody
    public Message delMechanic(Long id){
        Message message = new Message();
        Long proof = service.delMechanic(id);
        return message;
    }

    @RequestMapping(params = "method=updateMechanic")
    @ResponseBody
    public Message updateMechanic(Mechanic mechanic){
        Message message = new Message();
        Long proof = service.updateMechanic(mechanic);
        return message;
    }

}
